//
//  weightCollectionViewCell.m
//  Shine
//
//  Created by 俞青武 on 16/3/11.
//  Copyright © 2016年 王斌. All rights reserved.
//

#import "weightCollectionViewCell.h"
#import "PNChart.h"


@implementation weightCollectionViewCell

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView{
    self.backgroundColor = COLORBLACK;
    self.WeightLabel = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH_SCREEN *0.1, 0, WIDTH_SCREEN *0.3, WIDTH_SCREEN *0.3)];
    self.WeightLabel.font = [UIFont systemFontOfSize:20];
    self.WeightLabel.textAlignment = NSTextAlignmentCenter;
    self.WeightLabel.textColor = COLORWHITE;
    [self addSubview:self.WeightLabel];
    
    
    self.BMILabel = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH_SCREEN *0.55, 0, WIDTH_SCREEN *0.3, WIDTH_SCREEN *0.3)];
    self.BMILabel.textAlignment = NSTextAlignmentCenter;
    self.BMILabel.font = [UIFont systemFontOfSize:20];
    self.BMILabel.textColor = COLORWHITE;
    [self addSubview:self.BMILabel];
    
    
    self.WeightNumber = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH_SCREEN *0.05, WIDTH_SCREEN *0.08, WIDTH_SCREEN *0.4, WIDTH_SCREEN *0.4)];
    self.WeightNumber.textAlignment = NSTextAlignmentCenter;
    self.WeightNumber.font = [UIFont systemFontOfSize:38];
    self.WeightNumber.textColor = COLORYELLO;
    [self addSubview:self.WeightNumber];
    
    self.BMINumber = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH_SCREEN *0.5, WIDTH_SCREEN *0.08, WIDTH_SCREEN *0.4, WIDTH_SCREEN *0.4)];
    self.BMINumber.textAlignment = NSTextAlignmentCenter;
    self.BMINumber.font = [UIFont systemFontOfSize:38];
    self.BMINumber.textColor = COLORYELLO;
    [self addSubview:self.BMINumber];
    
    
    
    self.lineChart = [[PNLineChart alloc] initWithFrame:CGRectMake(20, WIDTH_SCREEN *0.6, WIDTH_SCREEN - 40, WIDTH_SCREEN *0.8)];
    self.lineChart.yLabelFormat = @"%1.1f";
    self.lineChart.backgroundColor = [UIColor clearColor];
    self.lineChart.xLabelColor = [UIColor colorWithWhite:0.902 alpha:1.000];
    [self.lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5",@"SEP 6",@"SEP 7"]];
    
    
    self.lineChart.showCoordinateAxis = YES;
    
    //Use yFixedValueMax and yFixedValueMin to Fix the Max and Min Y Value
    //Only if you needed
    self.lineChart.yFixedValueMax = 300.0;
    self.lineChart.yFixedValueMin = 0.0;
    self.lineChart.yLabelColor = [UIColor colorWithWhite:0.902 alpha:1.000];
    // Line Chart #1
    
    NSArray * data01Array = @[@75, @75, @75, @75.0, @75, @75, @75];
    
    PNLineChartData *data01 = [PNLineChartData new];
    data01.dataTitle = @"Alpha";
    data01.color = COLORYELLO;
    data01.alpha = 1;
    data01.itemCount = data01Array.count;
    data01.inflexionPointStyle = PNLineChartPointStyleCircle;
    //y轴赋值
    data01.getData = ^(NSUInteger index) {
        CGFloat yValue = [data01Array[index] floatValue];
        return [PNLineChartDataItem dataItemWithY:yValue];
    };
    self.lineChart.chartData = @[data01];
    [self.lineChart strokeChart];
    self.lineChart.delegate = self;

    
    [self addSubview:self.lineChart];
    
    self.numberLabel = [[UILabel alloc]init];
    self.numberLabel.textColor = COLORYELLO;
    self.numberLabel.textAlignment = NSTextAlignmentCenter;
    self.numberLabel.font = [UIFont systemFontOfSize:25];
    [self addSubview:self.numberLabel];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView).with.offset(0);
        make.centerY.equalTo(self.contentView).with.offset(-150);
        make.size.mas_equalTo(CGSizeMake(200,100));
    }];
    


}


//-(void)setDayArray:(NSMutableArray *)dayArray{
//    if (_dayArray != dayArray) {
//        _dayArray = dayArray;
//    }
//    self.arrayX = [NSArray arrayWithArray:self.dayArray];
//    [self.lineChart setXLabels:self.arrayX];
//    [self.lineChart strokeChart];
//
//}



- (void)userClickedOnLineKeyPoint:(CGPoint)point lineIndex:(NSInteger)lineIndex pointIndex:(NSInteger)pointIndex{
    NSString *newStr = [NSString stringWithFormat:@"%.1f%@",75.0,@"KG"];
    NSString *newStr1 = [NSString stringWithFormat:@"%@%@",@"您此时体重为",newStr];
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:newStr1];
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 6)];
    
    
    
    self.numberLabel.attributedText = str;
    
}

- (void)userClickedOnLinePoint:(CGPoint)point lineIndex:(NSInteger)lineIndex{
    NSLog(@"Click on line %f, %f, line index is %d",point.x, point.y, (int)lineIndex);
}

@end





















